import os
import pickle


def initListeADN(adn, listeAA):
    if(os.path.exists('atoaa.list')):
        return pickle.load(open('atoaa.list', 'r'))
    else:
        listeAlleleToAcideAmine = []
        c = 0
        for i in adn.listeAlleles():
            listeAlleleToAcideAmine.append([i.getId(), base10toN(c, listeAA)])
            c = c + 1

        #pickle.dump(listeAlleleToAcideAmine, open('atoaa.list', 'w+'))
        return listeAlleleToAcideAmine
        

def base10toN(num, listeAA):
    """function setId

    listeAA: <Allele>

    returns <Allele>
    """
    if (num == 0):
        return [0]
    arr = []
    base = len(listeAA)
    while num:
        rem = num % base
        num = num // base
        arr.append(rem)
    arr.reverse()
    return arr
